//index.js
import api from '../../tool/requestModel.js'
Page({
	data: {
		// 搜索框值
		searchValue: "",
		searchList: [],
		show: false,
		isShow: false,
		// 输入框焦点
		isfocus: false
	},
	searchBtn() {
		// 输入框中的值
		if (this.data.searchValue.trim() != '') {
			api.searchDetail({
				name: this.data.searchValue.trim()
			}).then(res => {
				console.log(res)
				this.setData({
					searchList: res.data.data
				})
				if (res.data.data.length == 0) {
					this.setData({
						show: true,
						isShow: true
					})
				}
			})
		} else {
			tt.showToast({
				title: "请输入完整",
				duration: 1500,
				icon: "none"
			})
		}
	},
	// 当输入框为空时，清空搜索的数据
	clearBtn(e) {
		console.log(e)
		this.setData({
			isShow: false,
			searchValue:e.detail.value
		})
		if (this.data.searchValue.trim() == '') {
			this.setData({
				searchList: []
			})
			return
		}
		api.searchDetail({
			name: this.data.searchValue.trim()
		}).then(res => {
			this.setData({
				searchList: res.data.data
			})
			if (res.data.data.length == 0) {
				this.setData({
					show: true,
					isShow: true
				})
			}
		})
	}
})
